import { _decorator, Canvas, Component } from 'cc';
import { ResManager } from  './common/res/ResManager';
import { UIManager, registerUINameBUrlByCfg } from './common/ui/UIManager';
import { PrefabCfg } from './auto/PrefabCfg';
import { Login } from './core/login/Login';
import { Play } from './core/play/Play'; 
const { ccclass } = _decorator;

// 全局变量声明
declare global {
    const game: Game;
}
@ccclass('Game')
class Game extends Component {
    readonly res = new ResManager();
    readonly ui = new UIManager();
    readonly login = new Login();

    async init(param: {canvas2d: Canvas, releaseBoostFun: Function, playerCanvas:  Canvas}) {
        // 全局变量设置
        (globalThis as any)["game"] = this;
        // 注册预制体信息
        registerUINameBUrlByCfg(PrefabCfg);
        // UI管理器初始化
        game.ui.init(param.canvas2d, param.playerCanvas);
        // 登录模块初始化
        game.login.init();
        
        // 显示登录界面（传入登录成功回调函数）
        this.login.showLogin(async () => {
            await game.ui.open(Play);
            param.releaseBoostFun();
        })
    }
}